<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="spring" 	uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="tiles" 	uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c"		uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" pageEncoding="utf-8"%>

<!-- URLs for reports -->
<c:url value="/reports/download" var="downloadUrl"/>
<c:url value="/reports/download/token" var="downloadTokenUrl"/>
<c:url value="/reports/download/progress" var="downloadProgressUrl"/>
<!-- end URLs for reports -->

<script type="text/javascript">
$(document).ready(function(){
	setMenuSelection("rapoarte");
	
	 $("#fromDate").kendoDatePicker({
    	 format: "dd.MM.yyyy"
    });
	 
	 $("#toDate").kendoDatePicker({
    	 format: "dd.MM.yyyy"
    });
	 
	 $("#fromDateAsigurari").kendoDatePicker({
    	 format: "dd.MM.yyyy"
    });
	 
	 $("#toDateAsigurari").kendoDatePicker({
    	 format: "dd.MM.yyyy"
    });
	 
	 
	 $("#fromDatePayments").kendoDatePicker({
    	 format: "dd.MM.yyyy"
    });
	 
	 $("#toDatePayments").kendoDatePicker({
    	 format: "dd.MM.yyyy"
    });	 
	
	// var serviceRoot = "http://demos.telerik.com/kendo-ui/service/Employees";
     treeSource = new kendo.data.HierarchicalDataSource({
         transport: {
             read: {
                 url: "json/domainsServicesTree",
                 dataType: "json"
             }
         },
         schema: {
             model: {
                 id: "id",
                 expanded: true,
                 children: "treeServices"
             }
         }
     });

	 $("#domeniiServiciiTree").kendoTreeView({
		   checkboxes: {
               checkChildren: true
           },
	     dataSource: treeSource,
	     dataTextField: "mdValue"
	 });


	 var domeniiServiciiTree = $("#domeniiServiciiTree").data("kendoTreeView");
	 domeniiServiciiTree.expand(".k-item");

	 $("#refBranch").kendoDropDownList({
         dataTextField: "mdValue",
         dataValueField: "id",
         dataSource: {
             transport: {
                 read: {
                     dataType: "json",
                     url: "json/listRefBranchREP",
                 }
             }
         }
     });
 
	 
	  // function that gathers IDs of checked nodes
     function checkedNodeIds(nodes, checkedNodes) {
         for (var i = 0; i < nodes.length; i++) {
             if (nodes[i].checked && !nodes[i].hasChildren) {
                 checkedNodes.push(nodes[i].id);
             }

             if (nodes[i].hasChildren) {
                 checkedNodeIds(nodes[i].children.view(), checkedNodes);
             }
         }
     }

     // show checked node IDs on datasource change
     $("#domeniiServiciiTree").data("kendoTreeView").dataSource.bind(
    		 "change", function() {
		         var checkedNodes = [], 
		             treeView = $("#domeniiServiciiTree").data("kendoTreeView"),
		             message;
		         
         			 checkedNodeIds(treeView.dataSource.view(), checkedNodes);
         			 
			         if (checkedNodes.length > 0) {
			             message = checkedNodes.join(",");
			         } else {
			             message ="";
			         }
			
			         $("#divServicesString").val(message);
     });
     
     
     
	 
	//report print function
/* VINZARI  - CONTRACTE */	
	$("#btGenerateRaportContracte").kendoButton({
		click: function(e) {
			$("#validationRaportContracteErrorMessage").text("");
			
			//var fromDateDatepicker = $("#fromDate").data("kendoDatePicker");
		 	//var fromDate =fromDateDatepicker.value();
		 	
		 	var fromDate = $("#fromDate").val();
		 	if (!fromDate) fromDate="";
		 	console.log(fromDate);
		 	
		 	console.log(" XXX = " + $("#toDate").val());
		 	
		 	
		 	//var toDateDatepicker = $("#toDate").data("kendoDatePicker");
		 	//var toDate =toDateDatepicker.value();
		 	var toDate = $("#toDate").val();
		 	if (!toDate) toDate="";
		 	console.log(toDate);
		 		
		 	var refBranchDropDownList = $("#refBranch").data("kendoDropDownList");
		 	var regionId = refBranchDropDownList.value();
		 	console.log(regionId);
		 	
		 	
		 	var servicesString = $("#divServicesString").val();
		 	console.log(servicesString);
		
		 	if (servicesString=="") {
		 		$("#validationRaportContracteErrorMessage").text("Nu sunt selectate serviciile! Verificati!");
		 		return;
		 	}
		 	
//		 	http://localhost:8080/mf/reports/getReportContractsList?dateFrom=&dateTo=&regionId=-1&servicesString=1,2
			window.open ('reports/getReportContractsList?dateFrom='+fromDate+'&dateTo='+toDate+'&regionId='+regionId+'&servicesString='+servicesString,'_blank',false);
		}
	});
	
/* ASIGURARI */
	$("#btGenerateRaportAsigurari").kendoButton({
		click: function(e) {
			$("#validationRaportAsigurariErrorMessage").text("");
		 	
		 	var fromDate = $("#fromDateAsigurari").val();
		 	if (!fromDate) fromDate="";
		 	console.log(fromDate);
		 	//console.log(" XXX = " + $("#toDate").val());

		 	var toDate = $("#toDateAsigurari").val();
		 	if (!toDate) toDate="";
		 	console.log(toDate);
		 		
			window.open ('reports/getReportAsigurari?dateFrom='+fromDate+'&dateTo='+toDate,'_blank',false);
		}
	});	
	
	//http://192.168.11.106:8080/mf/reports/getReportPayments?dateFrom=01.01.2014&dateTo=30.11.2014&pUtype=USR&pUid=7560 PRTNR
	 /* PLATI PE CONTRACTE */
		$("#btGenerateRaportPayments").kendoButton({
			click: function(e) {
				$("#validationRaportPaymentsErrorMessage").text("");
			 	
			 	var fromDate = $("#fromDatePayments").val();
			 	if (!fromDate) fromDate="";
			 	console.log(fromDate);
			 	//console.log(" XXX = " + $("#toDate").val());

			 	var toDate = $("#toDatePayments").val();
			 	if (!toDate) toDate="";
			 	console.log(toDate);
			 	
			 	var pRefUsrCB = $("#pRefUsr").data("kendoComboBox");
			 	if (pRefUsrCB.value().substring(0,1)=='-') {
			 		window.open ('reports/getReportPayments?dateFrom='+fromDate+'&dateTo='+toDate,'_blank',false);
			 	}
			 	var pId=pRefUsrCB.value().substring(1);
			 	if (pRefUsrCB.value().substring(0,1)=='U') {
			 		window.open ('reports/getReportPayments?dateFrom='+fromDate+'&dateTo='+toDate+'&pUtype=USR&pUid='+pId,'_blank',false);
			 	}
			 	if (pRefUsrCB.value().substring(0,1)=='P') {
			 		window.open ('reports/getReportPayments?dateFrom='+fromDate+'&dateTo='+toDate+'&pUtype=PRTNR&pUid='+pId,'_blank',false);
			 	}
			 	
				
			}
		});	
	 
	 
   	 $("#pRefUsr").kendoComboBox({dataSource: {
         type: "json",
         transport: {
             read: {
            	 url: "json/listSalariati"
             }
         }
     },
     dataTextField: "name",
     dataValueField: "id",
     placeholder:"Selectati"
     });
	  	
});



			  

</script>


<CENTER>
	<input id="divServicesString" style="visibility: hidden; width: 500px;" />
	<div id="tabReportVinzariParams" style="text-align: left; font-size: 12px; width: 900px; height: 410px; max-height: 410px;"  class="k-block k-shadow">
		<div class="k-header">Parametrii  "Raport vinzari"</div>
		<table style="width: 75%; border: 1px;" border="0" >
			<tr>
				<td style="width: 300px;">Selectati servicii</td>
				<td style="width: 200px;">Selectati Filiala</td>
				<td align="center">Data de la </td>
				<td align="center">Data pana la</td>
			</tr>
			<tr style="height: 300px; max-height: 300px; vertical-align: top;">
				<td style="border: 2px; border-style: inset;">
		            <div id="domeniiServiciiTree" style="height: 300px; max-height: 300px; width: 300px;"></div>
				</td>
				<td>
				    <div id="refBranch" style="width: 200px;"></div>
				</td>
				<td>
					<input id="fromDate" style="width: 100px;" />
				</td>
				<td>					
					<input id="toDate"   style="width: 100px;" />
				</td>
			</tr>
		</table>
		<p style="text-align: right;">
				<button id="btGenerateRaportContracte" type="button"	 >Genereaza raport</button>
		</p>		
	</div>
	<span id="validationRaportContracteErrorMessage" class="status" style="color: red; float: left;"></span>
	<br>
<!-- 	/*         */ -->
	<div id="tabReportAsigurariParams" style="text-align: left; font-size: 12px; width: 900px; height: 135px; max-height: 135px;"  class="k-block k-shadow">
		<div class="k-header">Parametrii  "Raport asigurari"</div>
		<table style="width: 75%; border: 1px;" border="0" >
			<tr>
				<td align="center">Data de la </td>
				<td align="center">Data pana la</td>
			</tr>
			<tr style="vertical-align: top;">
				<td align="center">
					<input id="fromDateAsigurari" style="width: 100px;" />
				</td>
				<td align="center">					
					<input id="toDateAsigurari"   style="width: 100px;" />
				</td>
			</tr>
		</table>
		<p style="text-align: right;">
				<button id="btGenerateRaportAsigurari" type="button"	 >Genereaza raport</button>
		</p>		
	</div>
	<span id="validationRaportAsigurariErrorMessage" class="status" style="color: red; float: left;"></span>
	
	<br>
<!-- 	/*         */ -->
	<div id="tabReportPaymentsParams" style="text-align: left; font-size: 12px; width: 900px; height: 180px; max-height: 180px;"  class="k-block k-shadow">
		<div class="k-header">Parametrii  "Raport Plati pe Contracte"</div>
		<table style="width: 100%; border: 1px;" border="0" >
			<tr>
				<td align="center">Data de la </td>
				<td align="center">Data pana la</td>
			</tr>
			<tr style="vertical-align: top;">
				<td align="center">
					<input id="fromDatePayments" style="width: 100px;" />
				</td>
				<td align="center">					
					<input id="toDatePayments"   style="width: 100px;" />
				</td>
			</tr>
			<tr>
				<td align="center">
					Pe persoana/partener
				</td>
				<td align="center"> 
					<select id="pRefUsr" style="width:300px;"> 
				</td>
			</tr>
		</table>
		<p style="text-align: right;">
				<button id="btGenerateRaportPayments" type="button"	 >Genereaza raport</button>
		</p>		
	</div>
	<span id="validationRaportPaymentsErrorMessage" class="status" style="color: red; float: left;"></span>	
	
</CENTER>



